from socket import *

path_file = r"D:\tyu.txt"


def re_file():  # 接收文件
    f = open(path_file, mode="wb")
    while True:
        data = client_socket.recv(data_size)
        f.write(data)
        if data is None:
            break
        f.flush()  # 来一点字节我就写入文件,并不缓存在内存中
    f.close()


ip = "192.168.0.105"
port = 6666
address = (ip, port)
data_size = 1024

tcp_serv_socket = socket(AF_INET, SOCK_STREAM)
tcp_serv_socket.bind(address)
tcp_serv_socket.listen(6)
print("----等待客户端连接----")
client_socket, client_address = tcp_serv_socket.accept()
print("等待客户机连接", str(client_address))

re_file()
tcp_serv_socket.close()
